package cn.jvm.str;

/**
 * @author summit
 * @since 2022/5/7 11:21
 */
public class StringTest {

	public static void main(String[] args) {
		String a = "a" + "b";
		System.out.println(a == "ab"); //true

		String str1 = "a";
		String str2 = "b";

		String str3 = str1 + str2;
		System.out.println(str3 == "ab");// false

		String str4 = new String("ma") + new String("y");	//true
		System.out.println(str4.intern() == str4);

		// java 关键字在常量池中就已经存在了 最后new  "java" 会新建一个，所以结果为false
		String str5 = new String("ja") + new String("va");	// false
		System.out.println(str5.intern() == str5);
	}
}
